<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<body>
<form class="bv-form" id="fileForm"  role="form" method="post" action="file/updateFile">
    <input type="hidden" name="fileId"  th:value="${entity.fileId}" />
    <div class="row">
        <div class="col-md-12">
            <div class="form-group" >
                <label for="fileScore">文档积分:</label>
                <input type="text" class="form-control" th:value="${entity.fileScore}" name="fileScore" id="fileScore"  placeholder="请输入文档积分" />
            </div>

            <div class="form-group">
                <label for="fileTypes">文档类型:</label>
                <select class="form-control" id="fileTypes">

                </select>
            </div>
            <div class="form-group">
                <label for="fileState">审核状态:</label>
                <select class="form-control" id="fileState">
                </select>
            </div>
        </div>
    </div>
</form>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $.post("dict/getType", { type: "FILE_TYPE" },
            function(r){
                /*  alert("Data Loaded: " + JSON.stringify(r));*/
                for ( var i = 0; i <r.data.length; i++){
                    /*alert(r.data[i].code);*/
                    console.log(r.data[i].code);
                    $("#fileTypes" ,window.top.document).append("<option name='fileTypes' th:value="+r.data[i].value+">"+r.data[i].text+"</option>")
                }
            })
        $.post("dict/getType", { type: "FILE_STATE" },
            function(r){
                /*  alert("Data Loaded: " + JSON.stringify(r));*/
                for ( var i = 0; i <r.data.length; i++){
                    /*   alert(r.data[i].code);*/
                    console.log(r.data[i].code);
                    $("#fileState", window.top.document).append("<option name='fileState' th:value="+r.data[i].value+">"+r.data[i].text+"</option>")
                }
            })


        $('#fileForm', window.top.document).bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {

                fileScore: {
                    message: '文档分数提交失败',
                    validators: {
                        notEmpty: {
                            message: '文档分数不可为空'
                        }
                    }
                },
                fileState: {
                    message: '文档状态提交失败',
                    validators: {
                        notEmpty: {
                            message: '文档状态不可为空'
                        }
                    }
                }
            }
        });

        // 绑定dialog的确定按钮的监听事件
        $("#btnOk",window.top.document).click(function() {
            $("#btnOk",window.top.document).attr("disabled",true);
            // 此段是为防止需要点击两次按钮来实现验证的方法，若不添加此处的放行，那么我们将要点击两次确定按钮才可以提交验证
            var fileId = $("#fileId", window.top.document).val();
           /* if(fileId != null && fileId != ""){
                $('#fileForm', window.top.document).bootstrapValidator('enableFieldValidators', 'code', false);
            } else {
                $('#fileForm', window.top.document).bootstrapValidator('enableFieldValidators', 'code', true);
            }*/
            var bootstrapValidator = $("#fileForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid()){
               /* alert($("#fileForm",window.top.document).serialize());
                alert($("#fileTypes").val());*/
                $.post($("#fileForm",window.top.document).attr('action'),$("#fileForm",window.top.document).serialize(),function(e){
                    if(e.result){
                        refreshDoQuery();
                    }else{
                        window.Ewin.alert({message:'修改数据失败!'});
                    }
                    $("#btnOk",window.top.document).attr("disabled",false);
                })
            }else{
                $("#btnOk",window.top.document).attr("disabled",false);
            }
        });

        // 重新刷新当前查询页的数据
        function refreshDoQuery(){
            var iframes = $(window.parent.document).contents().find(".J_iframe");
            for(var i=0;i<iframes.length;i++){
                if($(iframes[i]).css("display")=='inline'){
                    $('.modal-dialog', window.top.document).parent('div').remove()
                    $('body', window.top.document).find('.modal-backdrop').remove();
                    iframes[i].contentWindow.doQuery();
                    break;
                }
            }
        }
    })
</script>
</body>
</html>